package com.tianjipms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tianjipms.dao.BuildingMapper;
import com.tianjipms.entity.Building;
import com.tianjipms.service.BuildingService;
import com.tianjipms.utils.Result;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> implements BuildingService {
    @Resource
    public BuildingMapper buildingMapper;
    //车牌是否存在
    @Override
    public boolean existsByName(String name) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);
        return buildingMapper.exists(queryWrapper);
    }

    @Override
    public Result updateResidentNumById(Building building) {
        Building newBuilding = buildingMapper.selectById(building.getId());
        newBuilding.setResidentNum(building.getResidentNum() + 1);
        buildingMapper.updateById(building);
        return Result.ok();
    }
}
